/*
 * @Author: your name
 * @Date: 2021-10-11 20:00:16
 * @LastEditTime: 2021-10-11 20:48:54
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \luogu\1.5贪心\P3817\main.cpp
 */
#include<iostream>
using namespace std;
#define min(a,b) (a > b) ? b : a

const int MAX = 100;



int main(){
    int n,x;
    int a[MAX];
    cin >> n >> x;
    long long int sum0 = 0;
    for(int i=1; i<=n; i++){
        cin >> a[i];
        sum0 += a[i];
    }
    for(int i=2; i<=n-1; i++){
        if(a[i-1]+a[i] > x && a[i]+a[i+1] > x){
            int minNum = min(a[i-1],a[i+1]);
            a[i] = (minNum < x) ? x-minNum : 0;
        }
    }

    // for(int i=1; i<=n; i++){
    //     cout << a[i] << " ";
    // }
    // cout << endl;

    for(int i=1; i<n; i++){
        if(a[i]+a[i+1] > x){
            if(a[i+1] < x){
                a[i] = x-a[i+1];
            }else{
                a[i] = 0;
                a[i+1] = x;    
            }
        }
    }
    long long int sum1 = 0;
    for(int i=1; i<=n; i++){
        sum1 += a[i];
        // cout << a[i] << " ";
    }
    // cout << endl;
    cout << sum0-sum1 << endl;
}